<?php
namespace Apps\Csoap\Controllers;

use Phalcon\Mvc\Controller;
use Apps\Csoap\Controllers\BaseController;
use Phalcon\Http\Response;
use PhalconPlus\Common\ResponseResultStatus;
use Phalcon\Mvc\Model;
use Apps\Common\Models\BeautyParlor;
use Apps\Common\Models\BeautyParlorBrowseLog;

class BrowsecountController extends BaseController
{
    public function initialize(){
        parent::initialize();
    }
    /**
     * 获取7天浏览量
     * @date: 2016年2月27日 
     * @author: 545
     */
    public function countAction(){
        
        $this->view->disable();
        
        $shop_id = $this->getDataItem('shop_id');//分店id
       
        if (empty($shop_id)){
            $this->senderror(ResponseResultStatus::POST_BODY_PARAM_ERROR,'业务数据不全');
        }
        
        //获取美容院id
    	$bp_id  = BeautyParlor::findFirst("branch_id = {$shop_id}")->bp_id;
        
        if ($bp_id){
//             $count = BeautyParlorBrowseLog::count(['conditions'=> 'beauty_parlor_id = '.$bp_id.' AND DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= createtime']);
            
            $sql = "SELECT COUNT(*) AS rowcount FROM `beauty_parlor_browse_log` WHERE beauty_parlor_id = {$bp_id} AND DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= createtime";
            $model = new BeautyParlorBrowseLog();
            $rs = $model->getReadConnection()->query($sql)->fetchArray();
            $count = $rs['rowcount'];
            $this->sendResult(ResponseResultStatus::SUCCESS,['count'=>$count,'success'=>1],'');
        }
        else{
            $this->senderror(ResponseResultStatus::DATABASE_ERROR,'没有线上店铺');
        }
    }
}